package com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.dao;

import com.homedo.common.bean.vo.Pagination;
import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.po.AlertUser;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.query.AlertUserQuery;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.mapper.IAlertUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年10月16日 16时44分30秒
 */
@Repository
public class AlertUserDao extends BaseDao<AlertUser> {
    @Autowired
    private IAlertUserMapper alertUserMapper;

    public Pagination<AlertUser> getPagination(AlertUserQuery alertUserQuery, Pagination<AlertUser> pagination) {
        Example example = new Example(AlertUser.class);
        Example.Criteria criteria = example.createCriteria();

        if (Detect.notEmpty(alertUserQuery.getApplicationNames())) {
            criteria.andIn(AlertUser.FIELD_APPLICATIONNAME, alertUserQuery.getApplicationNames());
        }
        if (Detect.notEmpty(alertUserQuery.getLikeComment())) {
            criteria.andLike(AlertUser.FIELD_COMMENT, "%" + alertUserQuery.getLikeComment() + "%");
        }
        if (Detect.notEmpty(alertUserQuery.getLikeUsername())) {
            criteria.andLike(AlertUser.FIELD_USERNAME, "%" + alertUserQuery.getLikeUsername() + "%");
        }

        return super.getPagination(pagination, example);
    }
}
